import org.antlr.runtime.tree.*;
import org.antlr.runtime.*;

import java.util.List;

public class ExpressionTree extends CommonTree {
	public Object value;

	public ExpressionTree(int ttype)
	{
		super(new CommonToken(ttype));
	}

	public ExpressionTree(Token t)
	{
		super(t);
	}

	public ExpressionTree(ExpressionTree t)
	{
		super(t);
	}

	public Tree dupNode()
	{
		return new ExpressionTree(this);
	}

	public void evaluate()
	{
		if (value != null)
		{
			return;
		}
		switch (getToken().getType())
		{
		case CParser.DECIMAL_LITERAL:
			value = Integer.parseInt(getToken().getText());
			break;
		}
		if (getToken().getText().equals("+"))
		{
			ExpressionTree left = (ExpressionTree)getChild(0);
			ExpressionTree right = (ExpressionTree)getChild(1);
			left.evaluate();
			right.evaluate();
			if (left.value != null && right.value != null)
			{
				value = (Integer)left.value + (Integer)right.value;
			}
		}
	}
}